﻿
//加载左侧导航Tree
function GetNavigateContent(_Id, IsRemove) {
    var menu = $('.treemenu');
    menu.append("<ul class=\"menu_lv1\" style='margin-top:3px'></ul>");
    $.ajax(
    {
        type: "POST",
        url: 'Views/SystemLogin/GetCommanMenuById.aspx?Id=' + _Id,
        data: "",
        success: function(result) {
            //添加分类菜单      
            if (result.toString().toLowerCase() == "empty")//如果返回的是字符串"Empty"，表示是叶节点，不再继续加载
            {
                return false;
            }
            else if (result.toString().indexOf('<html>') == 0) {//包含<html>标签的是表示错误页面，不加载
                return false;
            }
            else {
                result = result.substring(0, result.indexOf("<html>"));
                var list = eval(result);
                var _data = [];
                //设置一个参量表示是否有tab
                var hasTab = false;
                $(list).each(function(i, item) {
                    var treenode = new TreeNodeData();
                    treenode.id = item.id;
                    treenode.pid = item.pid;
                    treenode.text = item.text;
                    treenode.attribute = item.attribute;
                    if (treenode.pid != "0") {
                        treenode.isexpand = false;
                    }
                    else {
                        treenode.isexpand = true;
                    }
                    _data.push(treenode);
                    //增加一个默认的tab                 
                    //增加一个tab
                    if (!hasTab) {
                        if (treenode.pid != 0 && treenode.attribute[0].url != '') {
                            //不需要关闭
                            if (tab.isTabItemExist('default') && IsRemove == true) {
                                tab.removeTabItem('default');
                                f_addTab(treenode.id, treenode.text, treenode.attribute[0].url, false);
                            }
                            hasTab = true; //改变状态，不再增加默认tab
                        }
                    }
                });
                var ajaxTree = menu.find('.menu_lv1');
                ajaxTree.ligerTree({
                    checkbox: false,
                    data: _data,
                    attribute: ['url'],
                    idFieldName: 'id',
                    parentIDFieldName: 'pid',
                    onClick: function(node) {
                        if (!node.data.attribute[0].url) return;
                        var tabid = $(node.target).attr("tabid");
                        var obj = $(">ul >li", tab.tab.links);
                        if (!tabid) {
                            tabid = node.data.id;
                            $(node.target).attr("tabid", tabid)
                        }
                        else {
                            tab.selectTabItem(tabid);
                            tab.reload(tab.getSelectedTabItemID());
                        }
                        if ($(">ul >li", tab.tab.links).length > 20) {
                            var currentTabid = $("li.l-selected", tab.tab.links).attr("tabid"); //当前选择的tabid
                            if (currentTabid == "default") return;
                            else {
                                //   tab.overrideTabItem(currentTabid, { tabid: tabid, url: node.data.attribute[0].url, text: node.data.text });
                                tab.removeTabItem(currentTabid);
                                f_addTab(tabid, treenode.text, treenode.attribute[0].url, false);
                                return;
                            }
                        }
                        f_addTab(tabid, node.data.text, node.data.attribute[0].url);
                    }
                });
            }
        }
    });
}

function TreeNodeData() {
    this.id;
    this.pid;
    this.text;
    this.isexpand;
    this.attribute;
}

//加载顶部导航菜单
function LoadAnimateMenu() {
    $.ajax({
        type: "get",
        url: "Views/systemLogin/GetNavigateMenu.aspx",
        data: "",
        cache: false,
        success: function(result) {
            //添加分类菜单      
            if (result.toString().toLowerCase() == "empty")//如果返回的是字符串"Empty"，表示是叶节点，不再继续加载
            {
                return false;
            }
            else if (result.toString().indexOf('<html>') == 0) {//包含<html>标签的是表示错误页面，不加载
                return false;
            }
            else {
                if (result == "" || result.toLowerCase().indexOf('<html>') == 0) {
                    alert("网络故障数据加载失败");
                }
                var Navigate = $('.animateMenu');
                result = result.substring(0, result.indexOf("<html>"));
                var list = eval(result);
                var shtml = "<ul>";
                $(list).each(function(i, item) {
                    shtml += "<li id='" + item.MENUID + "'><a href='javascript:void(0);' target='_blank'>" + item.MENUTEXT + "</a></li>";
                });
                shtml += "</ul>";
                Navigate.html(shtml);
                //在导航菜单上增加一个快捷菜单按钮
                LoadMenu($("#NavMenu"));
            }
        },
        error: function(xhq, textStatus, errorThrown) {
            alert(xhq.responseText);
        }
    });
}

function LoadMenu(menu) {
    var menu_anthour = menu.find("li a");
    // 把每个a中的内容包含到一个层（span.out）中，在span.out层后面追加背景图层（span.bg）
    menu_anthour.wrapInner('<span class="out"></span>').append('<span class="bg"></span>');

    // 循环为菜单的a每个添加一个层（span.over）
    menu_anthour.each(function() {
        $('<span class="over">' + $(this).text() + '</span>').appendTo(this);
        $(this).parent().bind('click',
		        function() {
		            var item = $(this);
		            var ojb = item.children().find('.out');
		            var _m_id = item.attr('id');
		            var _m_title = ojb.text();
		            if (_m_id == "ePlanet.Desktop") {
		                window.location.href = "index.aspx"; ;
		                return false;
		            }
		            else {
		                //注意，首页是弹出新窗口，子页面创建的时候是刷新链接
		                _m_id = encodeURIComponent(_m_id);
		                _m_title = encodeURIComponent(_m_title);
		                window.location.href = "Default2.aspx?id=" + _m_id + "&title=" + _m_title + "";
		                return false;
		            }
		        });
    });
}



  // 多选删除提示
function DeConfirm(listId, noSelectedString, deleteConfirmString) {
    var _noselectString = noSelectedString || "请选择要删除的项";
    var _deleteString = deleteConfirmString || "确定要删除吗?"
    var tbl = document.getElementById(listId);
    if (tbl != null) {
        var flag = false;
        for (var i = 1; i < tbl.childNodes[0].childNodes.length; i++) {
            var checkbox = tbl.childNodes[0].childNodes[i].childNodes[0].childNodes[0].childNodes[0];
            if (checkbox.type == "checkbox" && checkbox.checked == true) {          
                flag = true;
                break;
            }
        }
        if (!flag) {
            alert(_noselectString);
            return flag;
        }
    }
    return confirm(_deleteString);
}








